<template>
  <div class="project-display">
    <div class="pro-content">
      <div class="pro-info">
        <div class="pro-name">
          <div>{{ currentProject.name }}</div>
          <div style="margin-left: 16px; cursor: pointer">
            <a-dropdown @select="proChange">
              <icon-caret-down />
              <template #content>
                <a-doption
                  v-for="item in projectList"
                  :key="item.id"
                  :value="item"
                  >{{ item.name }}</a-doption
                >
              </template>
            </a-dropdown>
          </div>
        </div>
        <div class="pro-type">
          <a-tag color="cyan" size="medium">{{
            getTypeStr(currentProject.type)
          }}</a-tag>
        </div>
        <div class="pro-describe">
          {{ currentProject.description }}
        </div>
      </div>
      <div class="pro-cards">
        <div class="card-item bg1">
          <div class="title">项目编码</div>
          <div class="text">{{ currentProject.code || '' }}</div>
        </div>
        <div class="card-item bg2">
          <div class="title">项目预算</div>
          <div class="text">{{ currentProject.budget || 0 }} </div>
        </div>
        <!--        <div class="card-item bg3">-->
        <!--          <div class="title">项目模版</div>-->
        <!--          <div class="text"> </div>-->
        <!--        </div>-->
        <div class="card-item bg4">
          <div class="title">项目时间</div>
          <div class="text time-wrap">
            <div class="time" style="margin-top: 3px">
              {{ currentProject.planStart?.split(' ')[0] || '' }}
            </div>
            <span>至</span>
            <div class="time">
              {{ currentProject.planEnd?.split(' ')[0] || '' }}
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
  import { onMounted, ref } from 'vue';
  import {
    getProjectList,
    ProjectListParams,
    projectItem,
  } from '@/api/project';
  import { ProjectTypeMaps } from '@/directionary/project';

  const projectList = ref<projectItem[]>([]);
  const currentProject = ref({
    name: '',
    type: '',
    id: '',
    description: '',
    code: '',
    protemId: '',
    budget: '',
    planStart: '',
    planEnd: '',
  } as projectItem);

  const getList = () => {
    const params: ProjectListParams = {
      pageNo: 1,
      pageSize: 10,
      projectType: 0,
    };
    getProjectList(params).then((res: any) => {
      if (res.code === 8000000) {
        projectList.value = res.data?.list || [];
        if (projectList.value.length) {
          // eslint-disable-next-line prefer-destructuring
          currentProject.value = projectList.value[0];
        }
      }
    });
  };
  const getTypeStr = (type: string | number): string => {
    const proType: string = type as string;
    return ProjectTypeMaps[proType];
  };
  const proChange = (project: any) => {
    currentProject.value = project;
  };
  onMounted(() => {
    getList();
  });
</script>

<style scoped lang="less">
  .project-display {
    position: relative;
    //border: 1px solid red;
    height: 100%;
    width: 100%;
    .pro-content {
      height: 80%;
      background-color: var(--color-fill-2);
      position: absolute;
      bottom: 0;
      width: 100%;
      border-radius: 5px;
      .pro-info {
        width: 33%;
        //border: 1px solid red;
        height: calc(100% - 92px);
        margin-top: 46px;
        margin-left: 24px;
        display: flex;
        flex-direction: column;
        justify-content: center;
        .pro-name {
          font-size: 24px;
          font-family: Source Han Sans CN-Regular, Source Han Sans CN;
          font-weight: 400;
          color: #1d2129;
          line-height: 22px;
          display: flex;
          align-items: center;
          align-content: center;
        }
        .pro-type {
          margin-top: 16px;
        }
        .pro-describe {
          //word-break: break-all;
          padding-top: 8px;
          text-overflow: ellipsis;
          overflow: hidden;
          display: -webkit-box;
          -webkit-box-orient: vertical;
          -webkit-line-clamp: 2; /* 这里是超出几行省略 */
          font-size: 14px;
          font-family: Source Han Sans CN-Regular, Source Han Sans CN;
          font-weight: 400;
          color: #555555;
          line-height: 28px;
        }
      }
      .pro-cards {
        position: absolute;
        height: 100%;
        width: 58%;
        top: -25%;
        right: 24px;
        //border: 1px solid red;
        display: flex;
        justify-content: flex-end;
        .bg1 {
          background-image: url('@/assets/images/dashboard/bg-1.png');
        }
        .bg2 {
          background-image: url('@/assets/images/dashboard/bg-2.png');
        }
        .bg3 {
          background-image: url('@/assets/images/dashboard/bg-3.png');
        }
        .bg4 {
          background-image: url('@/assets/images/dashboard/bg-4.png');
        }
        .card-item {
          width: 23%;
          height: 100%;
          //border: 1px solid red;
          margin-left: 3%;
          background-position: center center;
          /* 背景图不平铺 */
          background-repeat: no-repeat;
          /* 让背景图基于容器大小伸缩 */
          background-size: cover;
          &:first-child {
            margin-left: 0;
          }
          .title {
            margin-top: 16px;
            margin-left: 16px;
            font-size: 16px;
            font-family: Source Han Sans CN-Medium, Source Han Sans CN;
            font-weight: 500;
            color: rgba(255, 255, 255, 0.8);
            line-height: 19px;
          }
          .text {
            width: calc(100% - 32px);
            margin-left: 16px;
            height: 66px;
            margin-top: 18px;
            line-height: 66px;
            text-align: center;
            white-space: nowrap;
            text-overflow: ellipsis;
            overflow: hidden;
            padding-left: 4px;
            padding-right: 4px;
            color: #ffffff;
            background: rgba(255, 255, 255, 0.15);
            border-radius: 4px 4px 4px 4px;
            opacity: 0.8;
            border: 1px solid;
            border-image: linear-gradient(
                90deg,
                rgba(255, 255, 255, 1),
                rgba(255, 251, 251, 0),
                rgba(255, 255, 255, 1)
              )
              1 1;
            border-radius: 4px !important;
          }
          .time-wrap {
            line-height: 20px;
          }
        }
      }
    }
  }
</style>
